<template>
  <div class="container">
    <nav-bar></nav-bar>
    <van-pull-refresh style="height:calc(100% - 48px)" v-model="refreshing" @refresh="onRefresh">
      <div class="item-box">
        <div class="content-box">
          <div class="top-total">
            <div class="left-total">
              <img src="../../../assets/img/view/volunteerTotal.png" alt="" />
              <div class="value-box">
                <div class="text-ch">志愿者总数（人）</div>
                <div class="text-num">
                  <count-to
                    :startVal="0"
                    :endVal="Number(state.info.volunteer)"
                    :decimals="0"
                    :duration="1000"
                  ></count-to>
                </div>
              </div>
            </div>
            <div class="middle-total">
              <img src="../../../assets/img/view/projectTotal.png" alt="" />
              <div class="value-box">
                <div class="text-ch">服务项目总数（个）</div>
                <div class="text-num">
                  <count-to
                    :startVal="0"
                    :endVal="Number(state.info.service)"
                    :decimals="0"
                    :duration="1000"
                  ></count-to>
                </div>
              </div>
            </div>
            <div class="right-total">
              <img src="../../../assets/img/view/timeTotal.png" alt="" />
              <div class="value-box">
                <div class="text-ch">服务总时长（时）</div>
                <div class="text-num">
                  <count-to
                    :startVal="0"
                    :endVal="Number(state.info.duration)"
                    :decimals="0"
                    :duration="2000"
                  ></count-to>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
      <div class="item-box" style="height:calc(100% - 145px)">
        <div class="ranking-box">
          <div class="top-title">
            <div class="title-box">
              <div class="title-text">积分榜单排名</div>
              <div class="title-tip">TOP10数据</div>
            </div>
            <div class="link-box" @click="toList">完整榜单&gt;</div>
          </div>
          <div class="content-list">
            <div class="title-line">
              <div class="columns1">排名</div>
              <div class="columns2">姓名</div>
              <div class="columns3">总时长</div>
              <div class="columns4">积分</div>
            </div>
            <div class="value-line" v-for="(item, i) in state.list" :key="i">
              <div class="columns1">
                <img
                  v-if="i === 0"
                  src="../../../assets/img/view/first.png"
                  alt=""
                />
                <img
                  v-if="i === 1"
                  src="../../../assets/img/view/second.png"
                  alt=""
                />
                <img
                  v-if="i === 2"
                  src="../../../assets/img/view/third.png"
                  alt=""
                />
                <div class="other-rank" v-else-if="i != 0 && i != 1 && i != 2">
                  {{ i + 1 }}
                </div>
              </div>
              <div class="columns2 overFlowLine1">{{ item.name }}</div>
              <div class="columns3 overFlowLine1">
                <!-- <count-to
                  :startVal="0"
                  :endVal="Number(item.totalDuration)"
                  :decimals="0"
                  :duration="1000"
                ></count-to> -->
                {{ item.totalDuration }}
              </div>
              <div class="columns4 overFlowLine1">
                <!-- <count-to
                  :startVal="0"
                  :endVal="Number(item.totalIntegral)"
                  :decimals="0"
                  :duration="1000"
                ></count-to> -->
                {{ item.totalIntegral }}
              </div>
            </div>
            <van-empty v-if="state.list.length == 0" description="暂无数据" />
          </div>
        </div>
      </div>
    </van-pull-refresh>
  </div>
</template>

<script setup>
import { ref, reactive, onBeforeMount, onMounted,inject } from 'vue'
import { get_timeBank_total, get_timeBank_list } from '@/api/xcc'
import router from '@/router/index'
import { useUserStore } from '@/pinia/modules/user'
import { useRouter } from 'vue-router'
import { CountTo } from 'vue3-count-to'

const changeComponents = inject('changeComponents')
const state = reactive({
  info: {},
  list: [],
  form:{},
  listForm: {
    pageSize: 10,
    pageNum: 1
  }
})
const loading = ref(false)
const refreshing = ref(false)
const finished = ref(false)

const onLoad = () => {
  getTotal()
  getList()
}

const onRefresh = () => {
  // 清空列表数据
  finished.value = false
  // 重新加载数据
  // 将 loading 设置为 true，表示处于加载状态
  loading.value = true
  state.listForm.pageNum = 1
  onLoad()
}

const toList = ()=>{
  changeComponents('list')
}

const getTotal = async () => {
  state.info = {}
  let res = await get_timeBank_total(state.form)
  if (res.succeed) {
    state.info = res.data
  }
}

const getList = async () => {
  if (refreshing.value) {
    state.list = []
    refreshing.value = false
  }
  let res = await get_timeBank_list(state.listForm)
  if (res.succeed) {
    state.list = res.data
  }
}

onMounted(() => {
  getTotal()
  getList()
})
onBeforeMount(() => {})
</script>

<style lang="less" scoped>
.container {
  overflow: auto;
  height: 100%;
  --fontColor1: #3852a9;
  --fontColor2: #219421;
  --fontColor3: #b95933;
  --fontColor4: #4375e4;
  background-color: #f8f8f8;
  // padding-top: 20px;
  .item-box {
    background-color: #fff;
    margin-top: 30px;
    .search-box {
      display: flex;
      height: 90px;
      width: 100%;
      border-bottom: 1px solid #e6e6e6;
      .left-box {
        height: 100%;
        :deep(.van-cell) {
          width: 220px;
          height: 100%;
          input {
            // max-width: 400px;
          }
        }
      }
    }
    .content-box {
      padding: 30px 0;
      .top-total {
        padding: 0 30px;
        display: flex;
        position: relative;
        .left-total {
          width: 100%;
          position: relative;
          // margin-right: 15px;
          display: flex;
          img {
            width: 100%;
          }
          .value-box {
            position: absolute;
            left: 50%;
            top: 50%;
            transform: translate(-50%, -50%);
            width: 100%;
            .text-ch {
              // padding-left: 15px;
              text-align: center;
              width: 100%;
              margin-bottom: 20px;
              font-size: 24px;
              font-weight: 400;
              color: var(--fontColor1);
            }
            .text-num {
              padding-left: 15px;
              width: 100%;
              font-size: 40px;
              font-weight: normal;
              color: var(--fontColor1);
            }
          }
        }
        .middle-total {
          width: 100%;
          position: relative;
          margin: 0 15px 0 15px;
          display: flex;
          img {
            width: 100%;
          }
          .value-box {
            position: absolute;
            left: 50%;
            top: 50%;
            transform: translate(-50%, -50%);
            width: 100%;
            .text-ch {
              text-align: center;
              width: 100%;
              margin-bottom: 20px;
              font-size: 24px;
              font-weight: 400;
              color: var(--fontColor2);
            }
            .text-num {
              padding-left: 15px;
              width: 100%;
              font-size: 40px;
              font-weight: normal;
              color: var(--fontColor2);
            }
          }
        }
        .right-total {
          width: 100%;
          // margin-left: 15px;
          position: relative;
          display: flex;
          img {
            width: 100%;
          }
          .value-box {
            position: absolute;
            left: 50%;
            top: 50%;
            transform: translate(-50%, -50%);
            width: 100%;
            .text-ch {
              text-align: center;
              width: 100%;
              margin-bottom: 20px;
              font-size: 24px;
              font-weight: 400;
              color: var(--fontColor3);
            }
            .text-num {
              padding-left: 15px;
              width: 100%;
              font-size: 40px;
              font-weight: normal;
              color: var(--fontColor3);
            }
          }
        }
      }
    }
  }
  .item-box {
    .ranking-box {
      margin-top: 20px;
      padding: 20px 0;
      .top-title {
        padding: 20px 30px;
        display: flex;
        align-items: center;
        justify-content: space-between;
        border-bottom: 1px solid #e6e6e6;
        .title-box {
          display: flex;
          align-items: flex-end;
          .title-text {
            font-size: 30px;
            font-family: Microsoft YaHei;
            font-weight: bold;
            color: #000000;
          }
          .title-tip {
            margin-left: 10px;
            font-size: 24px;
            font-family: PingFang SC;
            font-weight: bold;
            color: var(--fontColor4);
          }
        }
        .link-box {
          cursor: pointer;
          display: flex;
          font-size: 24px;
          font-family: PingFang SC;
          color: #999999;
        }
      }
      .content-list {
        .title-line {
          padding: 30px 0 15px 0;
          margin: 0 30px;
          display: flex;
          align-items: center;
          font-size: 24px;
          font-weight: bold;
          font-family: PingFang SC;
          color: var(--fontColor4);
          .columns1 {
            text-align: center;
            flex: 1;
          }
          .columns2 {
            text-align: center;
            flex: 1.5;
          }
          .columns3 {
            text-align: right;
            flex: 1.5;
          }
          .columns4 {
            text-align: right;
            flex: 1.5;
          }
        }
        .value-line {
          padding: 15px 0;
          margin: 0 30px;
          border-bottom: 1px solid #e6e6e6;
          display: flex;
          align-items: center;
          font-size: 30px;
          font-family: PingFang SC;
          color: #000;
          .columns1 {
            text-align: center;
            flex: 1;
            img {
              width: 30px;
              height: 51px;
            }
            .other-rank {
              text-align: center;
              width: 30px;
              height: 30px;
              background: #4375e4;
              border-radius: 30px;
            }
          }
          .columns2 {
            text-align: center;
            flex: 1.5;
          }
          .columns3 {
            text-align: right;
            flex: 1.5;
          }
          .columns4 {
            text-align: right;
            flex: 1.5;
          }
        }
      }
    }
  }
}
</style>
